import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:whale/helper/component/base/anchor/model.dart';

abstract class AnchorController extends GetxController
    with GetTickerProviderStateMixin {
  AnchorController({this.curr = 0});

  int curr;
  late TabController tabCtrl;
  late ScrollController sc;

  late final EasyRefreshController refreshCtrl =
      EasyRefreshController(controlFinishRefresh: true);

  late List<AnchorModel> list;

  List<String> get tabData => _tabData;
  set(List<String> tabData) {
    _tabData = tabData;
    _setupTab();
  }

  List<String> _tabData = [];

  /// 在 widget 内存中分配后立即调用。
  @override
  void onInit() {
    super.onInit();
  }

  /// 在 onInit() 之后调用 1 帧。这是进入的理想场所
  @override
  void onReady() {
    super.onReady();
  }

  /// 在 [onDelete] 方法之前调用。
  @override
  void onClose() {
    super.onClose();
  }

  /// dispose 释放内存
  @override
  void dispose() {
    super.dispose();
    tabCtrl.removeListener(() {});
    tabCtrl.dispose();
  }

  void onRefresh() async {}

  void _setupTab() {
    if (list.length == _tabData.length) return;
    tabCtrl = TabController(length: _tabData.length, vsync: this)
      ..addListener(() {});
  }

  void onScroll() {
    // sc.animateTo(offset, duration: duration, curve: curve)
  }
}
